/*
  HvacReset
  Part of the HVAC series of libraries for the Arduino.
  Example script to demonstrate calculating two temperature setpoints: 
  A condenser water temp setpoint (direct reset), and a hot water supply temp setpoint (reverse reset)...
 
  This example code is in the public domain.
  
  Matt Dobey
  3/13/2013
  version: 1_0
*/

//  Includes the HvacReset Library
#include <HvacReset.h>


/*  Direct Reset  */
//  A direct reset would be used for condenser water temp setpoint control..
//  Input - OA Temp
double cwsLowOaTempVal = 55.0;
double cwsHiOaTempVal = 75.0;

//  Output - Condenser Water Temp Setpoint
double cwsOutAtLowOaTempVal = 65.0;
double cwsOutAtHiOaTempVal = 85.0;

//  Creates an instance of HvacReset that we will use to calculate a setpoint.
HvacReset cwsTempReset(AUTOMATIC);

//  Condenser Water Supply Temp Setpoint Variable...  This would be the setpt input of a PID...
double cwsTempSetpt = 0.0;



/*  Reverse Reset  */
//  A reverse reset would be used for hot water supply temp setpoint control.
//  These variables can be changed on the fly in the loop.  
//  Input Variables - OA Temp
double hwsLowOaTempVal = 0.0;  //  Low OA Temp
double hwsHiOaTempVal = 60.0;  //  Hi OA Temp

//  Output Variables - HWS Temp Setpoint
double hwsOutAtLowOaTempVal = 180.0;  //  Output @ Low OA Temp
double hwsOutAtHiOaTempVal = 140.0;  //  Output @ Hi OA Temp


//  Creates an instance of HvacReset that we will use to calculate a setpoint.
HvacReset hwsTempReset(AUTOMATIC);

//  HWS Temp Setpoint Variable...  This would be the setpt input of a PID...
double hwsTempSetpt = 0.0;


//  Temporary Input Variable
double hwsOaTempVal = 30.0;
double cwsOaTempVal = 65.0;


void setup() {
  Serial.begin(9600);  // Initialize the serial port.
}



void loop() {
  //  Do something for the direct reset...
  Serial.print("Direct Reset Input : ");  Serial.print(cwsOaTempVal);  Serial.println(" deg F");
  cwsTempSetpt = hwsTempReset.reset(cwsOaTempVal, cwsLowOaTempVal, cwsHiOaTempVal, cwsOutAtLowOaTempVal, cwsOutAtHiOaTempVal);  
  Serial.print("Condenser Water Temp Setpoint Out : ");  Serial.print(cwsTempSetpt);  Serial.println(" deg F");

  Serial.println("");
  //  Do something for the reverse reset...
  Serial.print("Reverse Reset Input : ");  Serial.print(hwsOaTempVal);  Serial.println(" deg F");
  hwsTempSetpt = hwsTempReset.reset(hwsOaTempVal, hwsLowOaTempVal, hwsHiOaTempVal, hwsOutAtLowOaTempVal, hwsOutAtHiOaTempVal);  
  Serial.print("Hot Water Supply Temp Setpoint Out : ");  Serial.print(hwsTempSetpt);  Serial.println(" deg F");


  Serial.println("");  Serial.println("");  Serial.println("");
  delay(5000);  // Delay loop...
}

